package cn.edu.zafu.bigdata.x.zbw;

import java.util.Random;
import java.util.Scanner;

public class GuessNumberGame {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();

        int maxGuesses = 5; // 最大猜测次数
        int numberToGuess = random.nextInt(100) + 1; // 生成1到100之间的随机数
        int guess = 0;
        int attempts = 0;


        System.out.println("猜数字游戏开始！我已经想好了一个1到100之间的数字。");
        System.out.println("你有" + maxGuesses + "次机会来猜这个数字。");

        while (attempts < maxGuesses) {
            System.out.print("请输入你的猜测：");
            guess = scanner.nextInt();
            attempts++;

            if (guess == numberToGuess) {
                System.out.println("恭喜你！你猜对了数字是 " + numberToGuess + "。");
                break;
            } else if (guess < numberToGuess) {
                System.out.println("太小了，请再试一次。");
            } else if (guess > numberToGuess) {
                System.out.println("太大了，请再试一次。");
            }

            if (attempts == maxGuesses) {
                System.out.println("很遗憾，你的机会用完了。我想的数字是 " + numberToGuess + "。");
            }
        }

        scanner.close();
    }
}